import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
num_point = 100
vectors_set = []

for i in range(num_point):
    x1 = np.random.normal(0.0,0.55)
    y1 = x1 * 0.3 + 0.2 + np.random.normal(0.0,0.03)
    vectors_set.append([x1,y1])

x_data = [v[0] for v in vectors_set]
y_data = [v[1] for v in vectors_set]




W = tf.Variable(tf.random_uniform([1],-1.0,1.0,dtype=tf.float32),dtype=tf.float32,name='W')
b = tf.Variable(tf.zeros(1),dtype=tf.float32,name='b')
y = W * x_data + b

loss = tf.reduce_mean(tf.square(y-y_data),name='loss')

optimizer = tf.train.GradientDescentOptimizer(0.3)

train = optimizer.minimize(loss,name='train')

with tf.Session() as sess:
    init = tf.global_variables_initializer()
    sess.run(init)

    print(W.eval(),"b:",b.eval(),"loss:",loss.eval())

    for i in range(100):
        sess.run(train)
        print("w:",W.eval(),"b:",b.eval(),"loss:",loss.eval())


plt.scatter(x_data,y_data,c='r')
plt.scatter()
plt.show()

